// admin.js
const express = require('express')
const router = express.Router()

const AdminController = require('../controller/AdminController.js')

const multer = require('multer')

const path = require('node:path')

const uploadImg = multer({dest: path.join(__dirname, '../temp_imgs')})
const uploadVideo = multer({dest: path.join(__dirname, '../temp_videos')})

/**
 * 用户相关
 */
// 查询全部用户接口
router.get('/user', AdminController.searchUser)

// 条件查询用户接口
router.get('/user/:condition', AdminController.searchUser)

// 删除某个用户接口
router.delete('/user/:id', AdminController.deleteUser)

// 修改某个用户接口
router.put('/user/:id', AdminController.updateUser)

// 讲师列表接口
router.get('/teacher', AdminController.searchTeacher)

/**
 * 订单相关
 */
// 查询全部订单
router.get('/order', AdminController.searchOrder)

// 条件查询订单
router.get('/order/:condition', AdminController.searchOrder)

/**
 * 课程相关
 */
// 查询全部课程
router.get('/product', AdminController.searchProduct)

// 条件查询课程
router.get('/product/:condition', AdminController.searchProduct)

// 修改课程接口
router.put('/product/:id', AdminController.updateProduct)

// 删除课程接口
router.delete('/product/:id', AdminController.deleteProduct)

// 创建课程接口
router.post('/product', uploadImg.single('cover_img'), AdminController.addProduct)

// 获取课程章集
router.get('/product/chaptersAndEpisodes/:id', AdminController.getChaptersAndEpisodes)

/**
 * 视频相关
 */
// 获取视频字节数接口
router.post('/upload/check', AdminController.uploadCheck)

// 分片上传接口
router.post('/upload/chunk', uploadVideo.single('chunk'), AdminController.uploadChunk)

// 视频上传接口
router.post('/upload/hwcloud', AdminController.uploadHWCloud)

// 图片上传
router.post('/upload/image', uploadImg.single('image'), AdminController.uploadImage)

/**
 * 数据可视化大屏
 */
// 流量访问统计
router.get('/flow_stat', AdminController.flowStat)

// 终端类型分布图表
router.get('/device_type', AdminController.deviceType)

// top网站来源
router.get('/referer', AdminController.referer)

// 用户地域分布
router.get('/region', AdminController.region)

// 今日实时数据图表
router.get('/today_data', AdminController.todayData)

// 近期销售占比图表
router.get('/top_purchase', AdminController.topPurchase)

// 订单量趋势统计图表
router.get('/order_trend', AdminController.orderTrend)

// 用户量趋势统计图表
router.get('/user_trend', AdminController.userTrend)

module.exports = router